#include<iostream>
using namespace std;
bool judge(int n)
{
	int  t = n;
	int  sum = 0;
	while (t) {
		sum = sum * 10 + t % 10;
		t /= 10;
	}
	if (n == sum) {
		return 1;
	}
	return 0;
}
bool Prime(int n)
{
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			return 0;
		}
	}
	return 1;
}
int main()
{
	int  a, b;
	cin >> a >> b;
	if (b >= 1E7) {
		b = 9999999;
	}
	if (a % 2 == 0) {
		a++;
	}
	for (int i = a; i <= b; i+=2) {
		if (i % 2 == 0 && i != 2) {
			continue;
		}
		if (judge(i)&&Prime(i)) {
			cout << i << endl;
		}
	}
	return 0;
}